package com.simple.utils;

import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.DES;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName SimpleUtil
 * @Author SimpleTree
 **/
@Slf4j
public class SimpleUtil {

    /**
     * key：DES模式下，key必须为8位
     */
    public static String key = "12345678";
    /**
     * iv：偏移量，ECB模式不需要，CBC模式下必须为8位
     */
    public static String iv = "12345678";
    /**
     * 加解密类
     */
    private static DES des = new DES(Mode.CBC, Padding.PKCS5Padding, key.getBytes(), iv.getBytes());

    public static Double[] initDouble(Integer capacity) {
        Double[] doubles = new Double[capacity];
        for (int i = 0; i < doubles.length; i++) {
            doubles[i] = 0.0;
        }
        return doubles;
    }

    /**
     * arr ==> list
     * @param str
     * @return
     */
    public static List<Integer> arr2List(String str) {
        return Arrays.stream(str.split("-")).map(Integer::parseInt).collect(Collectors.toList());
    }

    /**
     * 加密
     */
    public static String encryPwd(String password) {
        return des.encryptBase64(password);
    }

    /**
     * 解密
     */
    public static String deEncryPwd(String password) {
        return des.decryptStr(password);
    }

    public static void main(String[] args) {
        String pwd = encryPwd("123456");
        System.out.println(pwd);
        System.out.println(deEncryPwd(pwd));
    }

    public static List<Double> double2List(Double[] doubles) {
        List<Double> list = new ArrayList<>();
        for (Double aDouble : doubles) {
            list.add(aDouble);
        }
        return list;
    }


}
